package com.service.admin.impl;

import com.dao.CommentDao;
import com.service.admin.AdminCommentService;
import com.utils.SqlSessionGetter;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdminCommentServiceImpl implements AdminCommentService {
  @Override
  public int getAllCommentCount() {
    SqlSession session = SqlSessionGetter.getSqlSession();
    CommentDao dao = session.getMapper(CommentDao.class);
    int count = dao.selectAllCommentCount();
    session.close();
    return count;
  }

  @Override
  public List<Map<String, Object>> getAllComments(int pageSize, int pageIndex) {
    SqlSession session = SqlSessionGetter.getSqlSession();
    CommentDao dao = session.getMapper(CommentDao.class);
    List<Map<String, Object>> comments = dao.selectAllComments(pageIndex * pageSize, pageSize);
    session.close();
    return comments;
  }
}
